package JavaBase;

/*
 *汽车(Car)有品牌(brand)、价格(price)、重量(weight)、当前油量(oilVolume)等属性，
 *       有行驶(run())、刹车(brake())、鸣笛(whistle())等方法。
 *       行驶中，油量会一直减少。当油量为0，汽车无法行驶。
 */
public class Car {
   private String brand;
   private double price;
   private double weight;
   private int oilVolum;
   public Car()
   {
       this.brand="大众PoLo";
       this.price=8;
       this.weight=1.2;
       this.oilVolum=10;
   }
   public Car(String brand,double price,double weight,int oilVolum)
   {
       this.brand=brand;
       this.price=price;
       this.weight=weight;
       this.oilVolum=oilVolum;
   }

    public double getPrice() {
        return price;
    }

    public double getWeight() {
        return weight;
    }

    public int getOilVolum() {
        return oilVolum;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public void setOilVolum(int oilVolum) {
        this.oilVolum = oilVolum;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }
    public void whistle()
    {
        System.out.println("嘀嘀~~~");
    }
    public void brake()
    {
        System.out.println("汽车刹住了！。。。。");
    }
    static public void time1s() {
        long start = System.currentTimeMillis();
        long end;
        do {
            end = System.currentTimeMillis();
        } while ((int) ((end - start) / 1000) < 1);
    }
    public void run()
    {
        while(this.oilVolum>=0)
        {
            System.out.println("汽车行驶中。。。");
            time1s();
            this.oilVolum--;
        }
        System.out.println("油量为0，汽车无法行驶");
    }
    public void carShow()
    {
        System.out.println("***汽车简介***");
        System.out.println("汽车品牌："+this.brand);
        System.out.println("汽车价格："+this.price);
        System.out.println("汽车重量："+this.weight);
    }
}
